package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;

public class Menu {
    private ArrayList<String> menu;
    private PrintStream printer;
    private BufferedReader reader;

    public Menu(PrintStream printer, BufferedReader reader) {
        this.printer = printer;
        this.reader = reader;
        menu = new ArrayList<String>();
        menu.add("1. Check membership");
        menu.add("2. Reserve Book");
        menu.add("3. Show books");
        menu.add("4. Show movies");
    }

    public int getSize() {
        return menu.size();
    }

    public int selectMenuOption(int menuSize) throws IOException {
        printer.println("Please select a menu option:");
        int input = Integer.parseInt(reader.readLine());
        if (validateUserInput(input, menuSize)) return input;
        return selectMenuOption(menuSize);
    }

    public ArrayList<String> getMenu() {
        return menu;
    }

    private boolean validateUserInput(int input, int menuSize) {
        if (input > 0 && input <= menuSize) {
            return true;
        }
        else {
            printer.println("Select a valid option!!");
            return false;
        }
    }
}